<?php echo $this->render('/public/header'); ?>
<?php use yii\helpers\Url; ?>
    <div id="main" class="col-xs-12">
        <button class="layui-btn layui-btn-normal" onclick="toggle_add()">添加后台用户</button>
        <br/>
        <br/>
        <div class="col-lg-6 col-md-6 col-sm-6">
            <table class="table table-borderd">
                <thead>
                <tr>
                    <th>id</th>
                    <th>name</th>
                    <th>角色</th>
                    <th>绑定职员</th>
                    <th>注册时间</th>
                </tr>
                </thead>
                <?php foreach ($this->params['list'] as $k => $v) { ?>
                    <tr>
                        <td><?php echo $v['id']; ?></td>
                        <td><?php echo $v['name']; ?></td>
                        <td><?php echo $v['role_name']; ?></td>
                        <td><?php echo $v['admin_name']; ?></td>
                        <td><?php echo date('Y-m-d H:i:s', $v['time']); ?></td>
                        <td>
                            <button onclick="del(<?php echo $v['id']; ?>)">删除员工</button>
                        </td>
                    </tr>
                <?php } ?>
            </table>
        </div>
        <div class="col-xs-5" id="add_user" style="display:none">
            <div class="form-group">
                <label for="exampleInputEmail1">名称</label>
                <input type="text" class="form-control" id="name" placeholder="账号">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">密码</label>
                <input type="text" class="form-control" id="password" placeholder="密码">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">角色</label>
                <select class="form-control" id="role">
                    <?php foreach ($this->params['role'] as $key => $v) { ?>
                        <?php if ($v['id'] == 1) {
                            continue;
                        } ?>
                        <option value="<?php echo $v['id']; ?>"><?php echo $v['role_name']; ?></option>
                    <?php } ?>
                </select>
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">绑定员工</label>
                <select class="form-control" id="staff_id">
                    <?php foreach ($this->params['staff_list'] as $key => $v) { ?>
                        <option value="<?php echo $v['id']; ?>"><?php echo $v['name']; ?></option>
                    <?php } ?>
                </select>
            </div>

            <button type="submit" class="btn btn-default" onclick="add_admin_user()">添加</button>
        </div>
    </div>
    <script>
        function toggle_add() {
            $("#add_user").toggle();
        }

        function add_admin_user() {
            if (layer.confirm('确认添加', {}, function () {
                    var name = $("#name").val();
                    var password = $("#password").val();
                    var role = $("#role").val();
                    var staff_id = $("#staff_id").val();
                    if (!(name || password || role || staff_id)) {
                        layer.alert('资料未完善');
                    }
                    var data = {name: name, password: password, role: role, staff_id: staff_id};
                    var url = "<?php echo Url::to(['setting/add_adminuser']);?>";
                    $.post(url, data, function (res) {
                        if (res.code == 1) {
                            layer.confirm(res.msg, {}, function () {
                                window.location.reload();
                            })
                        }
                        else {
                            layer.alert(res.msg);
                        }
                    }, 'json')
                })) ;
        }
    </script>
<?php echo $this->render('/public/footer'); ?>